/*******************************************************************************
 * Copyright (c) 2008, 2009 Fabio Mauro - Alberto Terraneo.
 * Permission is granted to copy, distribute and/or modify this document
 * under the terms of the GNU Free Documentation License, Version 1.2
 * or any later version published by the Free Software Foundation.
 *     
 * This program is distributed in the hope that it will be useful, 
 * but WITHOUT ANY WARRANTY; without even the implied 
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
 * See the GNU Free Documentation License for more details.
 *     
 * You should have received a copy of the GNU Free Documentation 
 * License along with this distribution; if not, send a email to authors:
 * aterraneo <at> users.sourceforge.net
 * bigmoby09 <at> users.sourceforge.net
 *******************************************************************************/
package it.blueocean.acanto.web.pages.secure.gruppo;

import it.blueocean.acanto.model.Gruppo;
import it.blueocean.acanto.service.GruppoService;
import it.blueocean.acanto.web.platform.components.panel.AcantoPanel;
import it.blueocean.acanto.web.platform.components.repeaters.AcantoDefaultDataTable;
import it.blueocean.acanto.web.platform.providers.AcantoProvider;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn;
import org.apache.wicket.extensions.markup.html.repeater.data.table.PropertyColumn;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.model.Model;
import org.apache.wicket.spring.injection.annot.SpringBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ListaGruppi extends AcantoPanel
{
	private static final long serialVersionUID = -8379002482509450699L;
	
	private static final Logger log = LoggerFactory.getLogger(ListaGruppi.class);

	@SpringBean
	private GruppoService gruppoService;

	@SuppressWarnings("unchecked")
	public ListaGruppi(String id)
	{
		super(id);
		add(new Label("name", "title : lista prodotti"));

		final AcantoProvider<Gruppo> dataProvider = new AcantoProvider<Gruppo>(getListGruppi(), "descrizione");

		IColumn<?>[] columns = new IColumn[2];
		columns[0] = new PropertyColumn(new Model("Identificativo"), "id");
		columns[1] = new PropertyColumn(new Model("Descrizione"), "descrizione");

		AcantoDefaultDataTable<Gruppo> dataTable = new AcantoDefaultDataTable("datatable", columns, dataProvider, 2);

		add(dataTable);
	}
	
	private List<Gruppo> getListGruppi()
	{
		List<String> eagerAttributes = new ArrayList<String>();
		eagerAttributes.add("famiglieAssociate");
		eagerAttributes.add("referenteSostituto");
		eagerAttributes.add("referentePrincipale");
		
		List<Gruppo> listGruppi = (List<Gruppo>)gruppoService.extractAll(eagerAttributes.toArray(new String[eagerAttributes.size()]));
		
		return listGruppi;
	}

}
